import { ipcMain, Menu, BrowserWindow } from 'electron'
import ipcEventChannels from '../../common/ipcEventChannels'

export default () => {
    ipcMain.on(ipcEventChannels.MENU_CHATLIST_SHOW, (event) => {
        const template = [
            {
                label: '查看资料',
                click() {
                    event.sender.send(ipcEventChannels.MENU_CHATLIST_CALLBACK, 'get-profile')
                }
            },
            { type: 'separator' },
            {
                label: '删除会话',
                click() {
                    event.sender.send(ipcEventChannels.MENU_CHATLIST_CALLBACK, 'delete')
                }
            }
        ]
        const menu = Menu.buildFromTemplate(template)
        menu.popup(BrowserWindow.fromWebContents(event.sender))
    })

    ipcMain.on(ipcEventChannels.MENU_MAINMENU_SHOW, (event) => {
        const template = [
            {
                label: '设置',
                click() {
                    event.sender.send(ipcEventChannels.MENU_MAINMENU_CALLBACK, 'setting')
                }
            },
            {
                label: '关于',
                click() {
                    event.sender.send(ipcEventChannels.MENU_MAINMENU_CALLBACK, 'about')
                }
            }
        ]
        const menu = Menu.buildFromTemplate(template)
        menu.popup(BrowserWindow.fromWebContents(event.sender))
    })
}
